﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ABFW
{
    /// <summary>
    /// AB包的依赖与引用关系
    /// </summary>
    public class ABRelation
    {
        // 当前AssetBundle 名称
        private string _ABName;
        // 本包所有的依赖包集合
        private List<string> _ListAllDependenceAB;
        // 本包所有的引用包集合
        private List<string> _ListAllReferenceAB;

        /// <summary>
        /// ctor两次tab
        /// </summary>
        public ABRelation(string abName)
        {
            if (!string.IsNullOrEmpty(abName))
            {
                _ABName = abName;
            }
            _ListAllDependenceAB = new List<string>();
            _ListAllReferenceAB = new List<string>();
        }

        /* 依赖关系 */
        //增加依赖关系
        public void AddDependence(string abName)
        {
            if (!_ListAllDependenceAB.Contains(abName))
            {
                _ListAllDependenceAB.Add(abName);
            }

        }
        /// <summary>
        /// 移除依赖关系
        /// </summary>
        /// <param name="abName">移除的包名称</param>
        /// <returns>
        /// true:此AssetBundle没有依赖项
        /// false:此AssetBundle还有其他依赖项
        /// </returns>
        public bool RemoveDependence(string abName)
        {
            if (_ListAllDependenceAB.Contains(abName))
            {
                _ListAllDependenceAB.Remove(abName);
            }

            if (_ListAllDependenceAB.Count > 0) return false;
            return true;
        }

        //获取所有依赖关系
        public List<string> GetAllDependence()
        {
            return _ListAllDependenceAB;
        }

        /* 引用关系 */
        //增加引用关系
        public void AddReference(string abName)
        {
            if (!_ListAllReferenceAB.Contains(abName))
            {
                _ListAllReferenceAB.Add(abName);
            }

        }
        /// <summary>
        /// 移除引用关系
        /// </summary>
        /// <param name="abName">移除的包名称</param>
        /// <returns>
        /// true:此AssetBundle没有引用项
        /// false:此AssetBundle还有其他引用项
        /// </returns>
        public bool RemoveReference(string abName)
        {
            if (_ListAllReferenceAB.Contains(abName))
            {
                _ListAllReferenceAB.Remove(abName);
            }

            if (_ListAllReferenceAB.Count > 0) return false;
            return true;
        }

        //获取所有引用关系
        public List<string> GetAllReference()
        {
            return _ListAllReferenceAB;
        }
    }
}
